﻿@{
	ViewBag.Title = "Manage Events";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@model  DirigoEdge.Areas.Admin.Models.ViewModels.ManageEventsViewModel


<div class="manageEvents module2">

    <div class="row">
        <div class="twelve columns">
            <h3><i class="fa fa-calendar"></i> Manage Events</h3>
            <a id="NewEventPage" class="button mobileBlockStatic mobileMarginBottom" href="@Url.Action("AddEvent", "Admin")">New Event +</a>
            <table class="twelve bordered manageTable" width="100%">
                <thead>
                    <tr>
                        <th>Title</th>
                        <th class="hide-for-small">Start Date</th>
                        <th class="hide-for-small">End Date</th>
                        <th class="hide-for-small">Created</th>
                        <th class="hide-for-small">Active</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @{
					    foreach(var thisEvent in Model.EventListing)
					    {
						    string active = thisEvent.IsActive ? "Yes" : "No";
                            <tr>
                                <td class="title"><a href="@Url.Action("EditEvent", "Admin", new { id = @thisEvent.EventId })">@thisEvent.Title</a></td>
                                <td class="hide-for-small">@Convert.ToDateTime(thisEvent.StartDate).ToString("MM/dd/yyyy")</td>
                                <td class="hide-for-small">@Convert.ToDateTime(thisEvent.EndDate).ToString("MM/dd/yyyy")</td>
                                <td class="hide-for-small">@Convert.ToDateTime(thisEvent.DateCreated).ToString("MM/dd/yyyy")</td>
                                <td class="hide-for-small">@active</td>
                                <td class="actions">
                                    <a class="delete button secondary small tabletMarginBottom" href="javascript:void(0);" data-id="@thisEvent.EventId">Delete</a>
                                    <a class="button secondary small mobileTop" href="/event/@DirigoEdge.Utils.ContentUtils.GetFormattedUrl(thisEvent.PermaLink)" target=_blank>Preview</a>
                                </td>
                            </tr>
					    }
                    }
                </tbody>
            </table>
        </div>
    </div>
</div>

@section Modals {
    <div id="DeleteModal" class="reveal-modal">
        <h2>Confirm Delete.</h2>
        <p class="lead">Are you sure you want to delete this event?</p>

        <p class=""><span id="popTitle"></span>will be <em>permanently</em> deleted.</p>

        <a id="ConfirmEventDelete" class="right button confirmModalButton mobileMarginBottom">Confirm</a>
        <a class="right button secondary" onclick="$('#DeleteModal').trigger('reveal:close');">Cancel</a>

        <a class="close-reveal-modal">&#215;</a>
    </div>
}

@section Scripts {
    @{
        // Only load if there is a good reason to
        if (Model.EventListing.Count > 0)
        {
            <script src="/Areas/Admin/Scripts/jquery/plugins/jquery.dataTables.min.js"></script>

            <script>
                $(document).ready(function () {
                    $("table.manageTable").dataTable({
                        "iDisplayLength": 25,
                        "aoColumnDefs": [
                            { "bSortable": false, "aTargets": ["actions"] } // No Sorting on actions
                        ],
                        "aaSorting": [[1, "desc"]] // Sort by publish date on load
                    });
                });
            </script>
        }
    }
}